package com.scpii.universal.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.scpii.universal.hibernate.dao.BaseDao;
import com.scpii.universal.hibernate.entity.AppViewCatelogRalationTab;
import com.scpii.universal.hibernate.intface.BaseInterface;
import com.scpii.universal.service.mobile.MobilePageService;
import com.scpii.universal.util.Const;
import com.scpii.universal.util.SQLs;


public class AppViewCatelogRalationTabService implements BaseInterface<AppViewCatelogRalationTab> {
	private static final Logger log = LoggerFactory
			.getLogger(AppViewCatelogRalationTabService.class);
	
//	private BaseDao<AppViewCatelogRalationTab> appViewCatelogRelationTabDao = SpringBeanFactory.appViewCatelogRelationTabDao;
	private BaseDao<AppViewCatelogRalationTab> appViewCatelogRelationTabDao;


	public AppViewCatelogRalationTab get(Integer id) throws Exception {
		return appViewCatelogRelationTabDao.get(id);
	}

	public List<AppViewCatelogRalationTab> getAll() throws Exception {
		return appViewCatelogRelationTabDao.getAll();
	}

	public AppViewCatelogRalationTab get(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public List<AppViewCatelogRalationTab> getList(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public Long getTotalCount() throws Exception {
		return null;
	}

	public void save(AppViewCatelogRalationTab obj) throws Exception {

	}

	public void update(AppViewCatelogRalationTab obj) throws Exception {

	}

	public void delete(AppViewCatelogRalationTab obj) throws Exception {

	}

	public void delete(Integer id) throws Exception {

	}

	public List<AppViewCatelogRalationTab> hqlGetList(String hql,
			Map<String, Object> argsMap) throws Exception {
		return appViewCatelogRelationTabDao.hqlGetList(hql, argsMap);
	}

	public void hqlUpdate(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		appViewCatelogRelationTabDao.hqlUpdate(namedHqlQuery, argsMap);
	}

	public Long hqlGetNums(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		return appViewCatelogRelationTabDao.hqlGetNums(namedHqlQuery, argsMap);
	}

	public List<AppViewCatelogRalationTab> sqlGetList(String sqls,
			Map<String, Object> argsMap) throws Exception {
		return appViewCatelogRelationTabDao.sqlGetList(sqls, argsMap);
	}

	public void sqlUpdate(String sqls, Map<String, Object> argsMap)
			throws Exception {
		appViewCatelogRelationTabDao.sqlUpdate(sqls, argsMap);
	}

	public Long sqlGetNum(String sqls, Map<String, Object> argsMap)
			throws Exception {
		return appViewCatelogRelationTabDao.sqlGetNum(sqls, argsMap);
	}
	
	/**
	 * 根据视图ID，获得在视图中显示的数据信息
	 * @param viewId
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-7-24下午03:29:31
	 */
	public List<AppViewCatelogRalationTab> getViewCateRelatByViewId(int viewId)throws Exception{
		if (viewId>0) {
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("viewId", viewId);
			List<AppViewCatelogRalationTab> appViewCateList = this.hqlGetList("GET_VIEW_CATE_BYVIEWID", argsMap);
			return appViewCateList;
		}
		return null;
	}
	
	/**
	 * 返回结果集的页数
	 * @param viewId
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-8-10下午04:03:26
	 */
	public Integer returnPageCountByViewId(int viewId)throws Exception{
		if (viewId>0) {
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("viewId", viewId);
			
			Long resultCount = this.hqlGetNums("GET_VIEW_CATE_COUNT_VIEWID", argsMap);
			int result = resultCount.intValue();
			int pageCount = appViewCatelogRelationTabDao.getRecordPageNum(result,Const.MOBILE_CLIENT_NO_PERPAGE);
			return pageCount;
		}
		return 0;
	}
	
	/**
	 * 根据视图ID，和页码，获得指定页码的数据
	 * @param viewId
	 * @param pageNum
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-8-10下午04:18:15
	 */
	public List<AppViewCatelogRalationTab> getViewCateListByViewId(int viewId,int pageNum)throws Exception{
		int MAXROWNUM = pageNum * Const.MOBILE_CLIENT_NO_PERPAGE;
		int MINROWNUM = (pageNum-1) * Const.MOBILE_CLIENT_NO_PERPAGE;
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("viewId", viewId);
		argsMap.put("MINROWNUM", MINROWNUM);
		argsMap.put("MAXROWNUM", MAXROWNUM);
		
		List<AppViewCatelogRalationTab> appViewCateRList = this.sqlGetList(SQLs.GET_VIEW_CATELOG_RELATION, argsMap);
		return appViewCateRList;
	}
	
	//Setter

	public void setAppViewCatelogRelationTabDao(
			BaseDao<AppViewCatelogRalationTab> appViewCatelogRelationTabDao) {
		this.appViewCatelogRelationTabDao = appViewCatelogRelationTabDao;
	}
	
}